package cosc617_blackteam;

import java.util.ArrayList;

/**
 * Menu Iterator for specialAttributes
 *
 * @author Anton
 */
public class SpecialAttributeMenuIterator implements I_MenuIterator
{

    ArrayList<MenuItem> menu;
    private int index;
    private MenuSpecialAttribute specialAttributeKey;

    public SpecialAttributeMenuIterator(ArrayList<MenuItem> menu, MenuSpecialAttribute specialAttributeKey)
    {
        index = 0;
        this.menu = menu;
        this.specialAttributeKey = specialAttributeKey;
    }

    @Override
    public boolean hasNext()
    {
        while(index < menu.size()) {
            if(menu.get(index).hasSpecialAttribute(this.specialAttributeKey)) {
                return true;
            }
            index++;
        }
        return false;
    }

    @Override
    public MenuItem next()
    {
        MenuItem output;
        if(hasNext()) //make sure there is a next and index is pointing to it
        {
            output = menu.get(index);
        } else {
            output = null;
        }
        index++;
        return output;
    }
    
	@Override
	public void remove() {
		throw new UnsupportedOperationException();
		
	}
}
